package com.ganee.agora.view

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.lifecycle.ViewModelProviders
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.ganee.agora.R
import com.ganee.agora.event.PostEvent
import com.ganee.agora.viewmodel.PostSuccessfullyViewModel
import com.ganee.baselib.arouter.Constance
import com.ganee.baselib.mvvmlibrary.base.BaseActivity
import kotlinx.android.synthetic.main.activity_post_successfully.*
import org.greenrobot.eventbus.EventBus

//发布成功页面
@Route(path = Constance.ACTIVITY_URL_POST_SUCCESSFULLY)
class PostSuccessfullyActivity : BaseActivity<PostSuccessfullyViewModel>(), View.OnClickListener {

    @JvmField
    @Autowired(name = "host")
    var host:String? = null

    override fun getViewModel(): PostSuccessfullyViewModel {
        return ViewModelProviders.of(this@PostSuccessfullyActivity).get(PostSuccessfullyViewModel::class.java)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_post_successfully)
        ARouter.getInstance().inject(this)
        successful_tv_tip.text = host + "," + "\n" + "Your event post was successful!"
        successful_tv_see.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when(v!!.id){
            R.id.successful_tv_see -> {
                ARouter.getInstance()
                        .build(Constance.ACTIVITY_URL_MAIN)
                        .withFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
                        .navigation()
                EventBus.getDefault().post(PostEvent("post"))
            }
        }
    }
}
